package cn.edu.sziit.bbs.controller;

import cn.edu.sziit.bbs.model.Post;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

//index.jsp
@Controller
public class IndexController {


    /**
     * 跳转到index.jsp页面
     *
     * @param session
     * @return
     */
    @RequestMapping(value = "/index", method = RequestMethod.GET)
    public String indexShow(HttpSession session) {
//        session.setAttribute("user", userService.selectByUsername("user5"));

        return "index";
    }

    /**
     * 退出帐号
     *
     * @param session
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/exit", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
    public Map<String, String> exit(HttpSession session) {
        session.invalidate();
        System.out.println("exit");
        Map<String, String> map = new HashMap<>();
        map.put("info", "退出成功");
        return map;
    }

    @RequestMapping(value = "/admin/index", method = RequestMethod.GET)
    public String adminIndexShow() {
        return "admin/index";
    }

}
